<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${r'${sysName}'}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${r'${resRoot}'}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${r'${resRoot}'}/css/main.css" media="all" />
	<link rel="stylesheet" href="${r'${resRoot}'}/layui/admin/admin.css" media="all" />
</head>
<body class="childrenBody">
	<div class="layui-fluid">   
          <div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	<form id="searchForm" class="layui-form layui-form-pane" method="post" action=""  >
		<#list table.fields as field>
			<#if field.isSelect?? && field.isSelect=="1">
				<div class="layui-inline">
			    <label class="layui-form-label">${field.comment!}</label>
			    <div class="layui-input-block">
			    <#if field.htmlType?? && field.htmlType=="3">
				      <select name="${field.propertyName}" id="${field.propertyName}" lay-filter="${field.propertyName}Change" >
				        <option value="">请选择${field.comment!}</option>
				      </select>
			   	<#else>
			   		<#if field.propertyType=="LocalDateTime">
				      <input type="text" class="layui-input" id="${field.propertyName}" name="${field.propertyName}"  onClick="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true});" placeholder="yyyy-MM-dd" value="${r'<#if'} ${table.entityPath}?? && ${table.entityPath}.${field.propertyName}?? ${r'>${'}${table.entityPath}.${field.propertyName}?datetime}${r'</#if>'}" >
				      <#elseif field.propertyType=="Long" || field.propertyType=="Double" || field.propertyType=="Integer">
				      <input type="number" name="${field.propertyName}" id="${field.propertyName}" value="${r'<#if'} ${table.entityPath}?? && ${table.entityPath}.${field.propertyName}?? ${r'>${'}${table.entityPath}.${field.propertyName}!}${r'</#if>'}"  autocomplete="off" placeholder="请输入${field.comment!}" class="layui-input">
				      <#else>
				      <input type="text" name="${field.propertyName}" id="${field.propertyName}" value="${r'<#if'} ${table.entityPath}?? && ${table.entityPath}.${field.propertyName}?? ${r'>${'}${table.entityPath}.${field.propertyName}!}${r'</#if>'}"  autocomplete="off" placeholder="请输入${field.comment!}" class="layui-input">
			    	  </#if>
			    </#if>
			    </div>
			  </div>
			</#if>
		</#list>
	
		<div class="layui-inline">
		    <button class="layui-btn search_btn" id=""  lay-submit="" lay-filter="searchDataBtn"  type="button">查询</button>
		</div>
		<div class="layui-inline">
			<a class="layui-btn linksAdd_btn" style="background-color:#5FB878" href="javascript:void(0);" onclick="openWin('${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/input',null,'添加');">添加</a>
			<a class="layui-btn linksAdd_btn" href="javascript:void(0);" onclick="exportExcel();">导出</a>
			
			${r'<@shiro.hasPermission'} name="${table.entityPath?substring(0, table.entityPath?length - 3)}:import">
			<a class="layui-btn linksAdd_btn" href="javascript:void(0);" onclick="importExcel();">导入</a>
		${r'</@shiro.hasPermission>'}
		</div>
		</form>
	<div class="layui-form member_list" style="margin-top: 10px;" >
	  	
	  	<table class="layui-hide" id="test" lay-filter="demo" ></table>
		<script type="text/html" id="barDemo">
		  <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
		  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>
	</div>
	</div>
	</div></div>
	${r'<#include "/page/footer.html">'}
	<script>
	
	$(function(){
		<#list table.fields as field>
		<#if field.htmlType?? && field.htmlType=="3">
		<#if field.dictValue??>
		setDictSelect("${field.propertyName}", "${field.dictValue!}", "");
		</#if>
		</#if>
		</#list>
		});
	
	var table;
	layui.use(['table', 'form'], function(){
		form = layui.form,
	  table = layui.table;
	  
	  table =  $.extend(table, {config: {checkName: 'checked'}});
	  table.render({
	    elem: '#test'
	    // 头部栏取消导出事件 'exports'
	    ,defaultToolbar: ['filter', 'print']
	    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
	    ,url:'${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/getPageData'
	    ,where:{
	    	
	    }
	    ,cols: [[
	    // 默认不开启合计，需要使用时自行开启合计功能， 并在render添加参数 totalRow: true  例如url:'https://www.layui.com/doc/modules/table.html#options'，在需要开启合计的行中添加 totalRow: true
	    // {type:'checkbox', fixed: true, disabled:true,totalRowText: '合计', checkbox:false},
	    { type: 'numbers', title: '序号', width: 80, fixed: 'left' },
    	<#list table.fields as field>
			<#if field.htmlType?? && field.htmlType=="3">
				// 字典
			{field:'${field.propertyName}', width:120, title: '${field.comment!}'<#if field.isShow?? && field.isShow=="1"><#else>,hide:true</#if>,templet :function (row){
	          return getDictLable('${field.dictValue!}',row.${field.propertyName});
	      }},
				<#else>
			<#if field.propertyType=="LocalDateTime">
			{field:'${field.propertyName}', width:120, title: '${field.comment!}'<#if field.isShow?? && field.isShow=="1"><#else>,hide:true</#if>,templet :function (row){
	          return createTime(row.${field.propertyName});
	      	}},
			<#else>
			{field:'${field.propertyName}', width:120, title: '${field.comment!}'<#if field.isShow?? && field.isShow=="1"><#else>,hide:true</#if>},
			</#if>
			</#if>
		</#list>
	      {fixed: 'right', width: 190, align:'center',title: '操作', toolbar: '#barDemo'}
	    ]]
	    ,loading:true
	    ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
		      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
		      //,curr: 5 //设定初始在第 5 页
		      ,groups: 5 //只显示 5 个连续页码
		      ,first: "首页" //显示首页
		      ,last: "尾页" //显示尾页
	}
	      ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
	    	  console.log(res)
	        return {
	          "code": res.message.code, //解析接口状态
	          "msg": res.message.msg, //解析提示文本
	          "count": res.message.count, //解析数据长度
	          "data": res.message.data //解析数据列表
	        };
	      }
	  });
	  
	      
	      var reloadTable = function (data) {
	          table.reload("test", { //此处是上文提到的 初始化标识id
	              where: data
	              ,page: { 
			      layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
			      ,groups: 5 //只显示 5 个连续页码
			      ,first: "首页" //显示首页
			      ,last: "尾页" //显示尾页
				}
	          });
	      };

	  
	//监听表格复选框选择
	  table.on('checkbox(demo)', function(obj){
		  console.log(obj.data)
	  });
	  
	  form.on('submit(searchDataBtn)', function(data){
			reloadTable(data.field)
	    });
	  
	  //监听工具条
	  table.on('tool(demo)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'detail'){
	      var url = "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/detial";
	      openWin(url,data.id,'查看详情');
	    } else if(obj.event === 'del'){
	        del(data.id);
	    } else if(obj.event === 'edit'){
	    	var url = "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/input";
	        openWin(url,data.id,'修改详情');
	    } 
	  });
	});
	
	document.onkeydown = function (event) {
        var e = event || window.event;
        if (e && e.keyCode == 13) { //回车键的键值为13
        	$(".search_btn").click(); //调用登录按钮的登录事件
        }
    }; 
	function exportExcel() {
		var index = layer.msg('加载中...',{icon: 16,time:false,shade:0.8});
		$("#searchForm").attr("action","${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/export");
		$("#searchForm").submit();
		layer.close(index);
	}
	
	  		function del(id){	
	  			layer.confirm('确定删除该条数据吗?', function(index){
  				 $.ajax({
  		    		 type : "post",
  		    		 url : "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/del",
  		    		 data : {
  		    			  id : id
  		    			 },
  					 dataType : "json",
  					 async : false,
  					 success : function(data) {
  						 flag  = data.message;
  							if(flag != 0) {
  								layer.msg('删除成功！', {
  									  icon: 1,
  									  time: 2000 //2秒关闭（如果不配置，默认是3秒）
  									}, function(){
  									  //do something
  										window.location.reload();
  									});  

  								
  							} else {
  								layer.alert("数据错误，请完善数据！");
  							}
  					 }
  		    	 });
  			});
		}
	  		
	  		function importExcel() {
	  			var url = "${r'${base}'}/sys/${table.entityPath?substring(0, table.entityPath?length - 3)}/toImport";
	  			var titleStr = "数据导入";
	  	        var index = layui.layer.open({
	  	            title : titleStr,
	  	            type : 2,
	  	            content : url,
	  	            success : function(layero, index){
	  	                var body = layui.layer.getChildFrame('body', index);
	  	                setTimeout(function(){
	  	                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
	  	                        tips: 3
	  	                    });
	  	                },500)
	  	            }
	  	        })
	  	        layui.layer.full(index);
	  	        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
	  	        $(window).on("resize",function(){
	  	            layui.layer.full(index);
	  	        })
	  		}

			function showPhoto(url) {
			var jsonstr = "{'title':'','id':123,'start':0,'data':[{'alt':'图1','pid':666,'src':'" + url +"','thumb':''}]}";
			var json = eval('(' + jsonstr + ')');
			layer.photos({
			photos: json
			,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
			});
			}
	  		
</script>
</body>
</html>